//banner部分

var mySwiper = new Swiper('.swiper', {
  navigation: {
    nextEl: '.swiper-button-next',
    prevEl: '.swiper-button-prev',
  },
  pagination: {
    el: '.swiper-pagination',
    clickable: true,
  },
  loop: true,
  autoplay: true,
  autoplay: {
    disableOnInteraction: false,
  }
})

/* api */

//获取元素
let apiDiv = document.querySelectorAll('.apibox div')
//console.log(apiDiv)

/* 
  需求: 1. 鼠标移入api-icon,改变api-icon的背景颜色
*/
apiDiv.forEach(function (dom, i) {
  dom.addEventListener('mouseover', function () {
    this.style.backgroundColor = 'skyblue'
    /* console.log(this.querySelector('img').src) */
    this.querySelector('img').src = `../imgs/api0${i + 1}-c.svg`

  })
})

/* 
  需求2: 2. 鼠标移出api.icon,api-icon改成原样
*/
apiDiv.forEach(function (dom, i) {
  dom.addEventListener('mouseout', function () {
    this.style.backgroundColor = '#fff'
    /* console.log(this.querySelector('img').src) */
    this.querySelector('img').src = `../imgs/api0${i + 1}.svg`
  })
})


/* 助力企业 */
/* 
  需求2: 每间隔2s就删除当前help-text类名active,并给下一个help-text添加active
*/
//获取元素
let helpList = document.querySelectorAll('.help-text')
let active = document.querySelector('.help-box .active')
let helpBox = document.querySelector('.help-box')
/* console.log(helpList)
console.log(active)
console.log(helpBox) */

//定义变量保存当前索引值
let index = 0
//开启计时器
let timeId = setInterval(horseLamp, 3000)
/* 
  需求: 当鼠标移入help-box时,关闭计时器
        当鼠标移出help-box时,重新开启计时器
*/
//移入
helpBox.addEventListener('mouseover', function () {
  clearInterval(timeId)
})

//移出
helpBox.addEventListener('mouseout', function () {
  timeId = setInterval(horseLamp, 3000)
})


function horseLamp() {

  helpList[index].classList.remove('active') //清除当前help-text的active

  ++index; //索引自增

  //判断
  if (index === helpList.length) index = 0

  helpList[index].classList.add('active')

}

/* 返回顶部 */
//获取元素
let reTop = document.querySelector('#reTop')

window.addEventListener('scroll', function () {
  //获取滚动距离
  let sTop = document.documentElement.scrollTop
  /* console.log(sTop) */

  if (sTop > 800) {
    reTop.style.display = 'block'
  } else {
    reTop.style.display = 'none'
  }

  /* 
    点击topBtn,回到顶部
  */
  reTop.addEventListener('click', function () {
    //window.scrollTo(0, 0)
    window.scrollTo({
      top: 0,
      behavior: 'smooth'
    })
  })
})